<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ReportModel extends CI_Model {
	protected $_table= "report";
	public function __construct()
	{
		parent::__construct();
		$this->load->database();
	}

	public function add($data)
	{
		$this->db->insert($this->_table,$data);
		return $this->db->insert_id();
	}

	public function get($id=0)
	{
		if (!is_numeric($id) || ($id < 0)) return false;
		if ($id>0){
			// $this->db->where('report.id',$id);
			// $this->db->order_by('report.id','desc');
			// $this->db->select('report.*');
			// $this->db->select('(SELECT COUNT(`id`) FROM report WHERE `report`.`id`=`id`) AS regNum', FALSE);
			// $q = $this->db->get('report');
			// return $q->result();
			$this->db->where('report.id',$id);
			$q = $this->db->get('report');
			if (!$q->num_rows()) return false;
			$result = $q->first_row();
			
			// if ($result->companyid > 0){
			// 	$this->db->where('id',$result->companyid);
			// 	$q = $this->db->get('company');
			// 	if ($q->num_rows()){
			// 		$q = $q->first_row();
			// 		$result->name = $q->name;
			// 	}
			// }
			
			return $result;
		}
	}
}
?>